package com.itheima.service.impl;

import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.itheima.mapper.HistoryMapper;
import com.itheima.service.HistoryService;
import com.itheima.ThreadLocalUtil;
import com.itheima.po.History;
import com.itheima.vo.HistoryVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author :wujunjie
 * createTime :2022-12-29 10:08
 * description :
 */
@Service
public class HistoryServiceImpl implements HistoryService {
    @Autowired
    private HistoryMapper historyMapper;
    @Override
    public List<HistoryVo> load() {
        LambdaQueryWrapper<History> lqw=new LambdaQueryWrapper<>();
        lqw.eq(History::getUserId, ThreadLocalUtil.getId());
        List<History> histories = historyMapper.selectList(lqw);
        return BeanUtil.copyToList(histories,HistoryVo.class);
    }

    @Override
    public Boolean del(String id) {
        LambdaQueryWrapper<History> lqw=new LambdaQueryWrapper<>();
        lqw.eq(History::getId,id);
        int delete = historyMapper.delete(lqw);
        return delete==1;
    }
}
